04. Segmenting the Plane with PCL

Header Text

Segmenting the Plane with PCL

ND313 C1 L2 A05 Using PCL To Segment Planne [LB]

Using PCL to segment Plane

In this exercise you will be separating the points that belong to the road from the points that belong to the scene.

The SegmentPlane Function Stub

Let's put the point processor to use now.

You will define the SegmentPlane function in src/processPointClouds.cpp . There is already a declaration for this function, and you just need to fill in the defintion. At the top of the function, you will notice a template parameter PointT . You will be using this as a variable to represent any type of point cloud, and it will come in handy later when you are processing point clouds with intensity values.

SegmentPlane Function Signature

 std::pair<typename pcl::PointCloud<PointT>::Ptr, typename pcl::PointCloud<PointT>::Ptr> SegmentPlane(typename pcl::PointCloud<PointT>::Ptr cloud, int maxIterations, float distanceThreshold);

The function accepts a point cloud, max iterations, and distance tolerance as arguments. Segmentation uses an iterative process. More iterations have a chance of returning better results but take longer. The segmentation algorithm fits a plane to the points and uses the distance tolerance to decide which points belong to that plane. A larger tolerance includes more points in the plane.

Have a look at the return type in the code above. SegmentPlane will return a std::pair holding point cloud pointer types. If you are not familiar with pairs check out the documentation here . You will use the pair object to hold your segmented results for the obstacle point cloud and the road point cloud. This way, you can later visualize both point clouds in the pcl viewer and analyze the results.

SegmentPlane Body

// Time segmentation process
auto startTime = std::chrono::steady_clock::now();

// TODO:: Fill in the function to segment cloud into two parts, the drivable plane and obstacles

auto endTime = std::chrono::steady_clock::now();
auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
std::cout << "plane segmentation took " << elapsedTime.count() << " milliseconds" << std::endl;

The first thing you see in the code above in the SegmentPlane function stub is a timer. This can be useful for measuring how long it takes to run the function. If it’s taking a really long time to process the segmentation, then the function is not going to be useful running in real-time on a self-driving car.

Instructions

To get started filling in the function you can use pcl’s segmentation object. For reference check out this pcl tutorial on segmentation . In particular check out lines 38-48. Have a look at the walkthrough below for an explanation of these lines, and try to implement them yourself in the workspace.

ND313 C1 L2 A06 Walking Through Pcl Segmentation

Instructions

Implement the SegmentPlane Function

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: react
  • Opened files (when workspace is loaded): n/a

Solution

Solution

ND313 C1 L2 A07 Segmenting Plane With PCL Solution